<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目任务完结申请管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="查看项目任务完结申请历史"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'projectTaskTaskDescription',width:120,align:'center'">任务描述</th>
				<th data-options="field:'applyPersonName',width:80,align:'center'">申请人</th>
				<th data-options="field:'applyTime',width:80,align:'center'">申请时间</th>
				<th data-options="field:'checkPersonName',width:80,align:'center'">审核人</th>
				<th data-options="field:'checkTime',width:80,align:'center'">审核时间</th>
				<th data-options="field:'status',width:60,align:'center'">任务状态</th>
				<th data-options="field:'id',width:40,align:'center',formatter:formatControl">详情</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<!-- 
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem')">新增</a>
		</div>
		 -->
		<div>
			申请时间: <input class="easyui-datetimebox" type="text" id="applyTimeBegin" style="width:150px;height:25px;">
			~ <input class="easyui-datetimebox" type="text" id="applyTimeEnd" style="width:150px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="项目任务完结申请详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td width="130px;" align="right">任务：</td>
						<td colspan="3">
							<input class="easyui-textbox" id="lookProjectTaskId" readonly="readonly" style="width: 505px;" />
						</td>
					</tr>
					<tr>
						<td width="130px;" align="right">职责：</td>
						<td colspan="3">
							<input class="easyui-textbox" id="lookProjectTaskPersonDuty" readonly="readonly" style="width: 505px;" />
						</td>
					</tr>
					<tr>
						<td align="right">申请时间：</td>
						<td>
							<input class="easyui-datetimebox" id="lookApplyTime" data-options="required:true" readonly="readonly" style="width: 200px;" />
						</td>
						<td align="right">状态：</td>
						<td>
							<input class="easyui-textbox" id="lookStatus" readonly="readonly" style="width: 200px;" />
						</td>
					</tr>
					<tr>
						<td align="right">申请说明：</td>
						<td colspan="3">
							<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 505px; height: 80px;" id="lookApplyDescription" readonly="readonly">
						</td>
					</tr>
					<tr>
						<td align="right">审核人：</td>
						<td>
							<input class="easyui-textbox" id="lookCheckPersonId" readonly="readonly" style="width: 200px;" />
						</td>
						<td align="right">审核时间：</td>
						<td>
							<input class="easyui-datetimebox" id="lookCheckTime" readonly="readonly" style="width: 200px;" />
						</td>
					</tr>
					<tr>
						<td align="right">审核意见：</td>
						<td colspan="3">
							<input class="easyui-textbox" data-options="multiline:true" style="width: 495px; height: 80px;" id="lookCheckComment" readonly="readonly">
						</td>
					</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="新增项目任务完结申请" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editProjectTaskFinishApply" style = "width:100%; height: 100%">
					<table width="100%" height="100%">
						<tr>
							<td width="130px;" align="right">项目名称：</td>
							<td>
								<select id = "addProject" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projects }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="130px;" align="right">任务：</td>
							<td>
								<select name = "projectTask.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectTasks }" >
										<option value = "${item.id }">${item.taskDescription }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">申请人：</td>
							<td>
								<select name = "applyPerson.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">申请时间：</td>
							<td>
								<input class="easyui-datetimebox" name="applyTime" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">状态：</td>
							<td colspan="3">
								<input class="easyui-textbox" name="status" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">申请说明：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 495px; height: 80px;" name="applyDescription">
							</td>
						</tr>
						<tr>
							<td align="right">审核人：</td>
							<td>
								<select data-options="editable: false" name = "checkPerson.id" class="easyui-combobox">
									<option value = ""> --请选择-- </option>
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">审核时间：</td>
							<td>
								<input class="easyui-datetimebox" name="checkTime" />
							</td>
						</tr>
						<tr>
							<td align="right">审核意见：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 495px; height: 80px;" name="checkComment">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="编辑项目任务完结申请" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editProjectTaskFinishApply" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<table width="100%" height="100%">
						<tr>
							<td width="130px;" align="right">项目名称：</td>
							<td>
								<select id = "editProject" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projects }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="130px;" align="right">任务：</td>
							<td>
								<select name = "projectTask.id" id="editProjectTaskId" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectTasks }" >
										<option value = "${item.id }">${item.taskDescription }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">申请人：</td>
							<td>
								<select name = "applyPerson.id" id="editApplyPersonId" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">申请时间：</td>
							<td>
								<input class="easyui-datetimebox" name="applyTime" id="editApplyTime" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">状态：</td>
							<td colspan="3">
								<input class="easyui-textbox" name="status" id="editStatus" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">申请说明：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 495px; height: 80px;" name="applyDescription" id="editApplyDescription">
							</td>
						</tr>
						<tr>
							<td align="right">审核人：</td>
							<td>
								<select data-options="editable: false" name = "checkPerson.id" id="editCheckPersonId" class="easyui-combobox">
								
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">审核时间：</td>
							<td>
								<input class="easyui-datetimebox" name="checkTime" id="editCheckTime" />
							</td>
						</tr>
						<tr>
							<td align="right">审核意见：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 495px; height: 80px;" name="checkComment" id="editCheckComment">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + row.id + ')">详情</a>'
			/*
			+
			' <a class="ctl" href="javascript:void(0)" onclick="editItem(' + val + ', ' + row.applyPersonId + ', ' + row.checkPersonId + ', ' + row.projectTaskId + ', ' + row.projectId + ', \'' + row.applyDescription + '\', \'' + row.applyTime + '\', \'' + row.checkTime + '\', \'' + row.status + '\', \'' + row.checkComment + '\')">编辑</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
			*/
		}
		function search(){
			var applyTimeBegin = $("#applyTimeBegin").textbox("getValue").trim();
			var applyTimeEnd = $("#applyTimeEnd").textbox("getValue").trim();
			var url = "queryProjectTaskFinishApply?projectTaskPersonId=${projectTaskPerson.id}&applyPersonId=${currentUser.id}&applyTimeBegin=" + applyTimeBegin + "&applyTimeEnd=" + applyTimeEnd;
			$("#dg").datagrid('reload', url);
		}
		function lookDetail(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findProjectTaskFinishApply",
			  	data: params,
			  	success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#lookProjectTaskId").textbox("setValue", item.projectTaskTaskDescription);
						$("#lookProjectTaskPersonDuty").textbox("setValue", item.duty);
						$("#lookApplyTime").textbox("setValue", item.applyTime);
						$("#lookStatus").textbox("setValue", item.status);
						$("#lookApplyDescription").textbox("setValue", item.applyDescription);
						$("#lookCheckPersonId").textbox("setValue", item.checkPersonName);
						$("#lookCheckTime").textbox("setValue", item.checkTime);
						$("#lookCheckComment").textbox("setValue", item.checkComment);
						
						$('#lookDetail').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function editItem(id){
			$("#editId").val(id);
			$("#editApplyPersonId").combobox("setValue", applyPersonId);
			$("#editCheckPersonId").combobox("setValue", item.checkPersonId);
			$("#editProjectTaskId").combobox("setValue", item.projectTaskName);
			$("#editProjectId").combobox("setValue", projectId);
			$("#editApplyDescription").textbox("setValue", applyDescription);
			$("#editApplyTime").textbox("setValue", applyTime);
			$("#editCheckTime").textbox("setValue", checkTime);
			$("#editStatus").textbox("setValue", status);
			$("#editCheckComment").textbox("setValue", checkComment);
			
			$('#editItem').window('open');
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的项目任务完结申请吗？", function(r){
				if(r){
					var params = "id=" + id;
					$.ajax({
					  	type: "GET",
					  	url: "delProjectTaskFinishApply",
					  	data: params,
					  	success:function(data){
						  	var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '删除成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  	}
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '添加成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '修改成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			//validateMenu
			search();//页面装载完成后加载数据
		});
	</script>
</body>
</html>